@extends('admin.default')
@section('title', '管理员列表')
@section('content')
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">

                        </div>
                        <div class="layui-card-header">

                            <button class="layui-btn" onclick="xadmin.open('添加用户','{{route('admin.manager.create')}}',500,600)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th>
                                    <input type="checkbox" name=""  lay-skin="primary">
                                  </th>
                                  <th>ID</th>
                                  <th>用户名</th>
                                  <th>姓名</th>
                                  <th>性别</th>
                                  <th>手机</th>
                                  <th>邮箱</th>
                                  <th>状态</th>
                                  <th>操作</th>
                              </thead>
                              <tbody>
                              @foreach($data as $val)
                                <tr>
                                  <td>
                                    <input type="checkbox" name=""  lay-skin="primary">
                                  </td>
                                  <td>{{$val->id}}</td>
                                  <td>{{$val->username}}</td>
                                  <td>{{$val->name}}</td>
                                  <td>@if($val->gender==1)男 @elseif($val->gender==2) 女 @else 保密 @endif</td>
                                  <td>{{$val->mobile}}</td>
                                  <td>{{$val->email}}</td>
                                  <td class="td-status">
                                      @if($val->status==1)
                                    <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span></td>
                                    @else
                                        <span class="layui-btn layui-btn-normal layui-btn-mini layui-btn-disabled">已停用</span></td>
                                    @endif
                                  <td class="td-manage">
                                    <a title="编辑"  onclick="xadmin.open('编辑','{{route('admin.manager.edit',$val->id)}}',500,600)" href="javascript:;">
                                      <i class="layui-icon">&#xe642;</i>
                                    </a>
                                    <a title="删除" onclick="manager_del('{{$val->id}}','{{route('admin.manager.destroy',$val->id)}}')" href="javascript:;">
                                      <i class="layui-icon">&#xe640;</i>
                                    </a>
                                  </td>
                                </tr>
                                  @endforeach
                              </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <script>
      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
      });
      function manager_del(id,url){
          layer.msg('你确定要删除该用户么？', {
              time: 0 //不自动关闭
              ,btn: ['确定', '取消']
              ,yes: function(index){
                  $.ajax({
                      type: 'POST',
                      url: url,
                      data:{
                          '_token':'{{csrf_token()}}',
                          '_method':'DELETE'
                      },
                      dataType: 'json',
                      success: function (data) {
                          if(data == 1){
                              layer.alert('删除成功', {
                                  icon: 1,
                                  skin: 'layui-layer-molv' //样式类名
                                  ,closeBtn: 0
                              }, function(){
                                  window.location.reload();
                              });
                          } else{
                              layer.alert('删除失敗', {
                                  icon: 2,
                                  skin: 'layui-layer-molv' //样式类名
                                  ,closeBtn: 0
                              });
                          }
                      }
                  });
              }
          });


      }
    </script>
@stop
